package com.four.peoplemanage.overtime.controller;

import com.four.peoplemanage.common.bean.ResponseData;
import com.four.peoplemanage.common.controller.BaseController;
import com.four.peoplemanage.overtime.entity.Overtime;
import com.four.peoplemanage.overtime.service.OvertimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/overtime")
public class OvertimeController extends BaseController {
    @Autowired
    OvertimeService overtimeService;

    //申请加班
    @PostMapping("/insert")
    public ResponseData<Boolean> insertOvertime(Overtime overtime){
        return returnBoolean(overtimeService.insert(overtime));
    }

    //分页
    @GetMapping("/getAll")
    public ResponseData<Object>  getAll(
            @RequestParam("pageNum") int pageNum,
            @RequestParam("pageSize") int pageSize,
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "overtime_type",required = false) String overtime_type,
            @RequestParam(value = "status",required = false) String status


    ){
        return returnObject(overtimeService.getAllOvertime(pageNum, pageSize, name, overtime_type,status));
    }
    //分页
    @GetMapping("/getone")
    public ResponseData<Object>  getOne(
            @RequestParam("pageNum") int pageNum,
            @RequestParam("pageSize") int pageSize,
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "overtime_type",required = false) String overtime_type,
            @RequestParam(value = "status",required = false) String status,
            @RequestParam(value = "information_id",required = false) int information_id


    ){
        return returnObject(overtimeService.getPageOvertime(pageNum, pageSize, name, information_id,overtime_type,status));
    }

    //更新状态可撤销
    @PutMapping("/updateS")
    public  ResponseData<Boolean> updateS(@RequestBody Overtime overtime){
        return returnBoolean(overtimeService.updateStatus(overtime));
    }
    //通过
    @PutMapping("/receive")
    public  ResponseData<Boolean> receive(@RequestBody Overtime overtime){
        return returnBoolean(overtimeService.updateSuccess(overtime));
    }
    //驳回
    @PutMapping("/reject")
    public  ResponseData<Boolean> reject(@RequestBody Overtime overtime){
        return returnBoolean(overtimeService.updateFail(overtime));
    }

    //编辑
    @PutMapping("/update")
    public ResponseData<Boolean> update(@RequestBody Overtime overtime){
        return returnBoolean(overtimeService.updateOvertime(overtime));
    }

}
